package com.midea.ai.air.ui.more.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.ui.more.data.MorePersonModel;

import java.util.List;

/**
 * Created by ouyangdi on 2016/4/11.
 * 更多->个人资料Adapter
 */
public class MorePersonAdapter extends ArrayAdapter<MorePersonModel> {
    private LayoutInflater mInflater;

    public MorePersonAdapter(Context context, List<MorePersonModel> objects) {
        super(context, 0, objects);
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        MorePersonModel item = getItem(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item_more, parent, false);
            holder = new ViewHolder();
            holder.tvName = (TextView)convertView.findViewById(R.id.txtView_name);
            holder.tvState = (TextView)convertView.findViewById(R.id.tv_state);
            holder.tvState.setVisibility(View.VISIBLE);
            holder.botLine = convertView.findViewById(R.id.bottom_line);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }

        holder.tvName.setText(item.getStrName());
        holder.tvState.setText(item.getStrState());
        if(position == getCount() -1) {
            holder.botLine.setVisibility(View.GONE);
        } else {
            holder.botLine.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    public class ViewHolder {
        public TextView  tvName;
        public TextView  tvState;
        public View botLine;
    }
}
